<!DOCTYPE html>
<html>

<head>
    <title>{$node.node_title}</title>
    {include file="common/header"/}

    <el-table :data="dataList.data"  v-loading="loading">
        <el-table-column prop="id" label="ID" align="center" width="100">
        </el-table-column>
        <el-table-column prop="name" label="name">
        </el-table-column>
        <el-table-column prop="ip" label="IP">
        </el-table-column>
        <el-table-column prop="domain" label="address">
        </el-table-column>
        <el-table-column prop="create_time" label="创建时间" align="center" width="200">
        </el-table-column>
        <el-table-column prop="update_time" label="最新时间" align="center" width="200">
        </el-table-column>
    </el-table>


    <div class="page">
        <el-pagination @size-change="handleSizeChange" :page-sizes="[10, 20, 50, 100,200,500]" :page-size="10"
            layout="total, sizes, prev, pager, next, jumper" background @current-change="changeCurrentPage"
            :current-page="dataList.current_page" :page-count="dataList.last_page" :total="dataList.total">
        </el-pagination>
    </div>

    {include file="common/footer"/}
    <script>
        var app = new Vue({
            el: '#app',
            data() {
                return {
                    loading: true,
                    dataList: [],
                    form: {
                        page: 1,
                        per_page: 10,
                        order: 'id desc'
                    },
                }
            },
            created() {
                this.getList();
            },
            methods: {
                handleSizeChange(per_page) {
                    this.form.per_page = per_page;
                    this.getList();
                },
                changeCurrentPage(page) {
                    this.form.page = page;
                    this.getList();
                },
                getList() {
                    var that = this;
                    that.loading = true;
                    axios.post('/admin/log/getList', Object.assign({}, PostBase, that.form))
                        .then(function (response) {
                            that.loading = false;
                            if (response.data.code == CODE_SUCCESS) {
                                that.dataList = response.data.data;
                                for (let i = 0; i < that.dataList.data.length; i++) {
                                    if(!that.dataList.data[i].domain){
                                        that.getAdd(i)
                                    }
                    			}
                            } else {
                                that.$message.error(response.data.message);
                            }
                        })
                        .catch(function (error) {
                            that.loading = false;
                            that.$message.error('服务器内部错误');
                        });
                },
                 getAdd(index){
                    var that = this;
                    axios.get('https://api.suyanw.cn/api/ipcha.php?ip='+that.dataList.data[index].ip)
                        .then(function (res) {
                            that.dataList.data[index].domain = res.data.text
                            axios.post('/admin/log/setDomain', Object.assign({}, PostBase, {
                                id: that.dataList.data[index].id,
                                domain: that.dataList.data[index].domain,
                            }))
                                .then(function (response) {
                                   
                                })
                                .catch(function (error) {
                                    that.loading = false;
                                    that.$message.error('服务器内部错误');
                                });
                        })
                },
            }
        })
    </script>


</html>